package com.mingsoft.led;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.mingsoft.led.util.Configure;

@Controller
public class LoginController {
	@RequestMapping(value = "/login")
	public String login(@RequestParam("password") String password,
			HttpSession session, ModelMap model) {
		if (password.equals(Configure.getInstance()
				.get(Configure.KEY_ADMIN_PWD))) {
			session.setAttribute("###LOGGED IN###", true);
			model.addAttribute("succeed", true);
			model.addAttribute("message", "welcome");
		} else {
			session.removeAttribute("###LOGGED IN###");
			model.addAttribute("succeed", false);
			model.addAttribute("message", "密码错误");
		}
		return "loginJSON";
	}

	@RequestMapping(value = "/guestLogin")
	public String gustLogin(HttpSession session, ModelMap model) {
		session.setAttribute("###LOGGED IN###", true);
		model.addAttribute("succeed", true);
		model.addAttribute("message", "welcome");
		return "loginJSON";
	}

	@RequestMapping(value = "/logoff")
	public String logoff(HttpSession session) {
		session.removeAttribute("###LOGGED IN###");
		return "login";
	}
}
